<?php

namespace app\stores\model\cash;

use app\cash\model\ServiceFeeModel;
use app\common\model\CommonModel;
use think\facade\Db;


class CashOrderSetModel extends CommonModel{

    protected  $name = 'cash_order_set';

    protected  $pk   = 'set_id';
    /**
     * 模型写入前事件（钩子函数）
     */
    public static function onBeforeInsert($model)
    {
        $model->set("add_time", date('Y-m-d H:i:s'));
        $model->set("edit_time", date('Y-m-d H:i:s'));
        $model->set("add_ip", request()->ip());
    }
    public static function info($where,$field='*')
    {
        $re = Db::name('cash_order_set')->where($where)->field($field)->find();
        if($re){
            $re['service_fee_list'] = [];
            if($re['service_fee_type']==1) $re['service_fee_list'] = ServiceFeeModel::list(['shop_id'=>$re['shop_id'],'is_delete'=>0],['add_time'=>'asc']);
        }
        return $re;
    }
    public static function up($data,$where){
        $data['edit_time']=date('Y-m-d H:i:s');
        $res=self::update($data,$where);
        return $res;
    }

}

